home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts26-11
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: How to read in binary file?
- Date: Wed, 06 Mar 96 07:09:44 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4hjdng$elu@sam.inforamp.net>
- References: <4lCptna00iV5Q5qSZK@andrew.cmu.edu>
- NNTP-Posting-Host: ts26-11.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4lCptna00iV5Q5qSZK@andrew.cmu.edu>,
- "Sang Hyun Park, Shawn" <sangp+@andrew.cmu.edu> wrote:
- >trial-1
- >------------------------------------------------------------------------
- >#include <fstream.h>
- >#include <string.h>
- >
- >void main(void)
- >{
- > short buf[2000]; // arbitrary size for trial
- >
- > ifstream ins("filename.bin");
- > ins.get(buf, 2000); *
- >
- >}
-
- Problems: A short is 16-bits or 2-bytes long.
- You should explicitly convert the buf variable.
- You should make the following change...
- ins.get((char *)buf, sizeof(short)*2000);
-
- I hope this helps.
-
- Agrivar
-